package com.example.cgpsys.beans;

import java.util.HashMap;

public class Result extends HashMap<String, Object>
{

    public Result()
    {
    }

    public Result(int code, String msg)
    {
        super.put("code", code);
        super.put("msg", msg);
    }

    public Result(int code, String msg, Object data)
    {
        super.put("code", code);
        super.put("msg", msg);
        if (data!=null)
        {
            super.put("data", data);
        }
    }

    public static Result success()
    {
        return Result.success("操作成功");
    }

    public static Result success(Object data)
    {
        return Result.success("操作成功", data);
    }

    public static Result success(String msg)
    {
        return Result.success(msg, null);
    }

    public static Result success(String msg, Object data)
    {
        return new Result(20000, msg, data);
    }

    public static Result error()
    {
        return Result.error("操作失败");
    }

    public static Result error(String msg)
    {
        return Result.error(msg, null);
    }

    public static Result error(String msg, Object data)
    {
        return new Result(40000, msg, data);
    }

    public static Result error(int code, String msg)
    {
        return new Result(code, msg, null);
    }

    @Override
    public Result put(String key, Object value)
    {
        super.put(key, value);
        return this;
    }
}
